import { Component } from "react"

class Counter extends Component {
  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this)
    // data
    this.state = {
      count: 0
    }
  }

  handleClick() {
    /*this.setState({
      count: this.state.count + 1
    })*/
    this.setState((state) => {
      console.log(state)
      return {
        count: state.count + 1
      }
    })
  }

  render() {
    const { title = "默认的title" } = this.props
    return (
      <div>
        <h3>{ title }</h3>
        <button onClick={ this.handleClick }>
          count++, { this.state.count }
        </button>
        {/*<button onClick={() => this.handleClick()}>
          count++, { this.state.count }
        </button>*/}
      </div>
    )
  }
}

export default Counter




